package demo;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import eventhandle.MyMouseListenerHandle;
import eventhandle.MyWindowEventHandle;
import eventhandle.MyWindowEventHandle2;

public class BorderLayoutDemo4 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame jf = new JFrame();
		JPanel jp = new JPanel();
		jp.setLayout(new FlowLayout());
		jp.add(new Button("6"));
		jp.add(new Button("7"));
		jp.add(new Button("8"));
		jp.add(new Button("9"));
		jf.setLayout(new BorderLayout(1,1));
		jf.add(new Button("1"),BorderLayout.EAST);
		jf.add(jp,BorderLayout.CENTER);
		jf.add(new Button("3"),BorderLayout.WEST);
		jf.add(new Button("4"),BorderLayout.NORTH);
		jf.add(new Button("5"),BorderLayout.SOUTH);
		jf.setVisible(true);
		jf.pack();
		JLabel lblNewLabel_1 = new JLabel("New label");
		lblNewLabel_1.setBounds(10, 30, 228, 15);
		jp.add(lblNewLabel_1);
		/*jf.addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent arg0) {		// 窗口被关闭窗口时触发
				System.out.println("windowClosed --> 窗口被关闭。");
				System.exit(1);
			}
		});*/
		jf.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				if(MouseEvent.BUTTON1 ==  e.getButton() && e.getClickCount() == 2 ){
					lblNewLabel_1.setText("双击鼠标左键");
				} else if ( MouseEvent.BUTTON2 == e.getButton() ){
					lblNewLabel_1.setText("按下了鼠标中键");
				} else {
					lblNewLabel_1.setText("按下了鼠标右键");
				}
			}
			@Override
			public void mousePressed(MouseEvent e) {
				lblNewLabel_1.setText( "X:" + e.getX() + "  Y:" + e.getY() );
			}
		});
	}

}
